package com.redteam.data.beans;

import com.redteam.data.enums.Endorsement;
import java.io.Serializable;
import java.sql.Date;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * A java bean for Airplanes
 * @author Jeremy Reed
 */
public final class Airplane extends RentalItem implements Serializable {

    private double hobbsLeftEngine, hobbsLastOverhaul,
            hobbsLastHundred, usableFuel,
            currentFuel, oilCapacity, currentOil;
    private String fuelGrade, oilGrade,
            tailNumber, manufacturer,
            model, imageLocation, dateAnnual, dateOverhaul, dateHundred;
    private Date dateLastOverhaul, annualDate,
            dateLastHundred;
    private int takeOffs, landings;
    private List<MaintenanceMemo> maintenanceMemo;
    private List<Endorsement> endorsements;
    private static final long serialVersionUID = 1L;

    /**
     * Default constructor
     */
    public Airplane() {
        super();
        maintenanceMemo = new ArrayList<MaintenanceMemo>();
        endorsements = new ArrayList<Endorsement>();
    }

    /**
     * Full Constructor for Airplane
     * @param id
     * @param fboID
     * @param rate
     * @param hobbsLeftEngine
     * @param hobbsLastOverhaul
     * @param hobbsLastHundred
     * @param usableFuel
     * @param currentFuel
     * @param oilCapacity
     * @param currentOil
     * @param fuelGrade
     * @param oilGrade
     * @param tailNumber
     * @param manufacturer
     * @param model
     * @param dateLastOverhaul
     * @param annualDate
     * @param dateLastHundred
     * @param type
     * @param aircraftType
     * @param takeOffs
     * @param landings
     */
    public Airplane(Long id, Long fboID, double rate, double hobbsLeftEngine, double hobbsLastOverhaul,
            double hobbsLastHundred, double usableFuel, double currentFuel, double oilCapacity,
            double currentOil, String fuelGrade, String oilGrade, String tailNumber, String manufacturer,
            String model, Date dateLastOverhaul, Date annualDate, Date dateLastHundred, String type,
            String aircraftType, int takeOffs, int landings) {

        super(id, fboID, rate, type, aircraftType);
        System.out.println("Making Airplanes");
        maintenanceMemo = new ArrayList<MaintenanceMemo>();
        endorsements = new ArrayList<Endorsement>();
        this.setStringDates(dateLastOverhaul, annualDate, dateLastHundred);
        this.setHobbsLeftEngine(hobbsLeftEngine);
        this.setHobbsLastOverhaul(hobbsLastOverhaul);
        this.setHobbsLastHundred(hobbsLastHundred);
        this.setUsableFuel(usableFuel);
        this.setCurrentFuel(currentFuel);
        this.setOilCapacity(oilCapacity);
        this.setCurrentOil(currentOil);
        this.setFuelGrade(fuelGrade);
        this.setOilGrade(oilGrade);
        this.setTailNumber(tailNumber);
        this.setManufacturer(manufacturer);
        this.setModel(model);
        this.setDateLastOverhaul(dateLastOverhaul);
        this.setAnnualDate(annualDate);
        this.setDateLastHundred(dateLastHundred);
        this.setTakeOffs(takeOffs);
        this.setLandings(landings);
        this.setImageLocation(imageLocation);



    }

    /**
     * Returns a list of maintenance memos
     * @return A list of maintenance memos
     */
    public List<MaintenanceMemo> getMaintenanceMemo() {
        return maintenanceMemo;
    }

    /**
     * Sets the Airplane's maintenance memo list
     * @param maintenanceMemo a list maintenance memos
     */
    public void setMaintenanceMemo(List<MaintenanceMemo> maintenanceMemo) {
        this.maintenanceMemo = maintenanceMemo;
    }

    /**
     * Returns the Airplane's annual date
     * @return the airplane's annual date
     */
    public Date getAnnualDate() {
        return annualDate;
    }

    /**
     * Sets the annual date
     * @param annualDate yearly maintenance date
     */
    public void setAnnualDate(Date annualDate) {
        this.annualDate = annualDate;
    }

    /**
     * Returns the amount of current fuel available.
     * @return currentFuel
     */
    public double getCurrentFuel() {
        return currentFuel;
    }

    /**
     * Set or update the amount of current fuel available.
     * @param currentFuel
     */
    public void setCurrentFuel(double currentFuel) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.currentFuel = Double.valueOf(twoDForm.format(currentFuel));
    }

    /**
     * Returns the current oil level.
     * @return currentOil
     */
    public double getCurrentOil() {
        return currentOil;
    }

    /**
     * Set or update the amount of the current oil
     * @param currentOil
     */
    public void setCurrentOil(double currentOil) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.currentOil = Double.valueOf(twoDForm.format(currentOil));

    }

    /**
     * Returns the date of the last hundred
     * @return dateLastHundred
     */
    public Date getDateLastHundred() {
        return dateLastHundred;
    }

    /**
     * Sets the date of the last hundred
     * @param dateLastHundred
     */
    public void setDateLastHundred(Date dateLastHundred) {
        this.dateLastHundred = dateLastHundred;
    }

    /**
     * Returns the date of the last overhaul
     * @return dateLastOverhaul
     */
    public Date getDateLastOverhaul() {
        return dateLastOverhaul;
    }

    /**
     * Sets the date of the last overhaul
     * @param dateLastOverhaul
     */
    public void setDateLastOverhaul(Date dateLastOverhaul) {
        this.dateLastOverhaul = dateLastOverhaul;
    }

    /**
     * Returns the fuel grade
     * @return fuelGrade
     */
    public String getFuelGrade() {
        return fuelGrade;
    }

    /**
     *Sets the fuel grade
     * @param fuelGrade
     */
    public void setFuelGrade(String fuelGrade) {
        this.fuelGrade = fuelGrade;
    }

    /**
     * Returns the last hundred hobbs
     * @return hobbsLastHundred
     */
    public double getHobbsLastHundred() {
        return hobbsLastHundred;
    }

    /**
     *  Set or update the last hundred hobbs
     * @param hobbsLastHundred
     */
    public void setHobbsLastHundred(double hobbsLastHundred) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.hobbsLastHundred = Double.valueOf(twoDForm.format(hobbsLastHundred));
    }

    /**
     * Return hobbs Last overhaul
     * @return hobbsLastOverhaul
     */
    public double getHobbsLastOverhaul() {
        return hobbsLastOverhaul;
    }

    /**
     * Set or update the hobbs last overhaul
     * @param hobbsLastOverhaul
     */
    public void setHobbsLastOverhaul(double hobbsLastOverhaul) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.hobbsLastOverhaul = Double.valueOf(twoDForm.format(hobbsLastOverhaul));

    }

    /**
     * Returns the hobbs left on the engine
     * @return hobbsLeftEngine
     */
    public double getHobbsLeftEngine() {
        return hobbsLeftEngine;
    }

    /**
     * Set or update the hobbs left on the engine
     * @param hobbsLeftEngine
     */
    public void setHobbsLeftEngine(double hobbsLeftEngine) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.hobbsLeftEngine = Double.valueOf(twoDForm.format(hobbsLeftEngine));
    }

    /**
     * Returns the airplane manufacturer
     * @return manufacturer
     */
    public String getManufacturer() {
        return manufacturer;
    }

    /**
     * Sets the airplane manufacturer
     * @param manufacturer
     */
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    /**
     * Returns the airplane model
     * @return model
     */
    public String getModel() {
        return model;
    }

    /**
     * Sets the airplane model
     * @param model
     */
    public void setModel(String model) {
        this.model = model;
    }

    /**
     * Returns the oil capacity of the plane.
     * @return oilCapacity
     */
    public double getOilCapacity() {
        return oilCapacity;
    }

    /**
     * Sets the oil capacity of the plane.
     * @param oilCapacity
     */
    public void setOilCapacity(double oilCapacity) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.oilCapacity = Double.valueOf(twoDForm.format(oilCapacity));
    }

    /**
     * Returns the oil grade to be used
     * @return oilGrade
     */
    public String getOilGrade() {
        return oilGrade;
    }

    /**
     * Sets the oil grade to be used
     * @param oilGrade
     */
    public void setOilGrade(String oilGrade) {
        this.oilGrade = oilGrade;
    }

    /**
     * Returns the tail number.
     * @return tailNumber
     */
    public String getTailNumber() {
        return tailNumber;
    }

    /**
     *Sets the tail number
     * @param tailNumber
     */
    public void setTailNumber(String tailNumber) {
        this.tailNumber = tailNumber;
    }

    /**
     * Returns the Amount of fuel left
     * @return usableFuel
     */
    public double getUsableFuel() {
        return usableFuel;
    }

    /**
     * Updates or sets the usable fuel
     * @param usableFuel
     */
    public void setUsableFuel(double usableFuel) {
        DecimalFormat twoDForm = new DecimalFormat("#.#");
        this.usableFuel = Double.valueOf(twoDForm.format(usableFuel));

    }

    /**
     * Returns the image path
     * @return imageLocation
     */
    public String getImageLocation() {
        return imageLocation;
    }

    /**
     * Sets the image path
     * @param imageLocation
     */
    public void setImageLocation(String imageLocation) {
        this.imageLocation = imageLocation;
    }

    /**
     * Returns a List containing all the endorsements
     * @return endorsementList
     */
    public List<String> getEndorsements() {
        List<String> endorsementList = new ArrayList<String>();
        for (Endorsement e : endorsements) {
            endorsementList.add(e.toString());
        }
        return endorsementList;
    }

    /**
     * Update or set the Endorsements
     * @param endorsements
     */
    public void setEndorsements(List<String> endorsements) {
        for (String s : endorsements) {
            this.endorsements.add(Endorsement.valueOf(s));
        }
    }

    /**
     * Returns the number of landings
     * @return landings
     */
    public int getLandings() {
        return landings;
    }

    /**
     *Sets the number of landings
     * @param landings
     */
    public void setLandings(int landings) {
        this.landings = landings;
    }

    /**
     * Returns the number of takeOffs
     * @return takeOffs
     */
    public int getTakeOffs() {
        return takeOffs;
    }

    /**
     * update the number of takeOffs
     * @param takeOffs
     */
    public void setTakeOffs(int takeOffs) {
        this.takeOffs = takeOffs;
    }

    /**
     *
     * @return
     */
    public String getDateOverhaul() {
        return dateOverhaul;
    }

    /**
     *
     * @return
     */
    public String getDateAnnual() {
        return dateAnnual;
    }

    /**
     *
     * @return
     */
    public String getDateHundred() {
        return dateHundred;
    }

    /**
     *
     * @param dateOverhaul
     * @param dateAnnual
     * @param dateHundred
     */
    public void setStringDates(Date dateOverhaul, Date dateAnnual, Date dateHundred) {
        String[] dateinfo = dateOverhaul.toString().split("-");
        StringBuilder sb = new StringBuilder();
        sb.append(dateinfo[1]).append("/").append(dateinfo[2]).append("/").append(dateinfo[0]);
        this.dateOverhaul = sb.toString();
        dateinfo = dateOverhaul.toString().split("-");
        sb = new StringBuilder();
        sb.append(dateinfo[1]).append("/").append(dateinfo[2]).append("/").append(dateinfo[0]);
        this.dateAnnual = sb.toString();
        dateinfo = dateOverhaul.toString().split("-");
        sb = new StringBuilder();
        sb.append(dateinfo[1]).append("/").append(dateinfo[2]).append("/").append(dateinfo[0]);
        this.dateHundred = sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Airplane other = (Airplane) obj;
        if (Double.doubleToLongBits(this.hobbsLeftEngine) != Double.doubleToLongBits(other.hobbsLeftEngine)) {
            return false;
        }
        if (Double.doubleToLongBits(this.hobbsLastOverhaul) != Double.doubleToLongBits(other.hobbsLastOverhaul)) {
            return false;
        }
        if (Double.doubleToLongBits(this.hobbsLastHundred) != Double.doubleToLongBits(other.hobbsLastHundred)) {
            return false;
        }
        if (Double.doubleToLongBits(this.usableFuel) != Double.doubleToLongBits(other.usableFuel)) {
            return false;
        }
        if (Double.doubleToLongBits(this.currentFuel) != Double.doubleToLongBits(other.currentFuel)) {
            return false;
        }
        if (Double.doubleToLongBits(this.oilCapacity) != Double.doubleToLongBits(other.oilCapacity)) {
            return false;
        }
        if (Double.doubleToLongBits(this.currentOil) != Double.doubleToLongBits(other.currentOil)) {
            return false;
        }
        if ((this.fuelGrade == null) ? (other.fuelGrade != null) : !this.fuelGrade.equals(other.fuelGrade)) {
            return false;
        }
        if ((this.oilGrade == null) ? (other.oilGrade != null) : !this.oilGrade.equals(other.oilGrade)) {
            return false;
        }
        if ((this.tailNumber == null) ? (other.tailNumber != null) : !this.tailNumber.equals(other.tailNumber)) {
            return false;
        }
        if ((this.manufacturer == null) ? (other.manufacturer != null) : !this.manufacturer.equals(other.manufacturer)) {
            return false;
        }
        if ((this.model == null) ? (other.model != null) : !this.model.equals(other.model)) {
            return false;
        }
        if ((this.imageLocation == null) ? (other.imageLocation != null) : !this.imageLocation.equals(other.imageLocation)) {
            return false;
        }
        if (this.dateLastOverhaul != other.dateLastOverhaul && (this.dateLastOverhaul == null || !this.dateLastOverhaul.equals(other.dateLastOverhaul))) {
            return false;
        }
        if (this.annualDate != other.annualDate && (this.annualDate == null || !this.annualDate.equals(other.annualDate))) {
            return false;
        }
        if (this.dateLastHundred != other.dateLastHundred && (this.dateLastHundred == null || !this.dateLastHundred.equals(other.dateLastHundred))) {
            return false;
        }
        if (this.takeOffs != other.takeOffs) {
            return false;
        }
        if (this.landings != other.landings) {
            return false;
        }
        if (this.maintenanceMemo != other.maintenanceMemo && (this.maintenanceMemo == null || !this.maintenanceMemo.equals(other.maintenanceMemo))) {
            return false;
        }
        if (this.endorsements != other.endorsements && (this.endorsements == null || !this.endorsements.equals(other.endorsements))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.hobbsLeftEngine) ^ (Double.doubleToLongBits(this.hobbsLeftEngine) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.hobbsLastOverhaul) ^ (Double.doubleToLongBits(this.hobbsLastOverhaul) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.hobbsLastHundred) ^ (Double.doubleToLongBits(this.hobbsLastHundred) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.usableFuel) ^ (Double.doubleToLongBits(this.usableFuel) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.currentFuel) ^ (Double.doubleToLongBits(this.currentFuel) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.oilCapacity) ^ (Double.doubleToLongBits(this.oilCapacity) >>> 32));
        hash = 29 * hash + (int) (Double.doubleToLongBits(this.currentOil) ^ (Double.doubleToLongBits(this.currentOil) >>> 32));
        hash = 29 * hash + (this.fuelGrade != null ? this.fuelGrade.hashCode() : 0);
        hash = 29 * hash + (this.oilGrade != null ? this.oilGrade.hashCode() : 0);
        hash = 29 * hash + (this.tailNumber != null ? this.tailNumber.hashCode() : 0);
        hash = 29 * hash + (this.manufacturer != null ? this.manufacturer.hashCode() : 0);
        hash = 29 * hash + (this.model != null ? this.model.hashCode() : 0);
        hash = 29 * hash + (this.imageLocation != null ? this.imageLocation.hashCode() : 0);
        hash = 29 * hash + (this.dateLastOverhaul != null ? this.dateLastOverhaul.hashCode() : 0);
        hash = 29 * hash + (this.annualDate != null ? this.annualDate.hashCode() : 0);
        hash = 29 * hash + (this.dateLastHundred != null ? this.dateLastHundred.hashCode() : 0);
        hash = 29 * hash + this.takeOffs;
        hash = 29 * hash + this.landings;
        hash = 29 * hash + (this.maintenanceMemo != null ? this.maintenanceMemo.hashCode() : 0);
        hash = 29 * hash + (this.endorsements != null ? this.endorsements.hashCode() : 0);
        return hash;
    }
}
